package com.dlc.felear.xiaoensale.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dlc.felear.xiaoensale.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class BlueToothItemAdapter extends BaseAdapter {

    private static final String TAG = "IoItemAdapter";
    // 上下文
    private Context context;
    // 数据
    private List<String> data;

    public BlueToothItemAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }


    public void setItems(Map<String, String> data) {
        this.data.clear();
        if (data != null && !data.isEmpty()) {
            this.data.addAll(data.values());
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        data.clear();
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Integer getItem(int position) {
        return 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = View.inflate(context, R.layout.adapter_blue_tooth_item, null);
                holder.tv_name = convertView.findViewById(R.id.tv_name);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.tv_name.setText(data.get(position));
        }catch (Exception e){

        }
        return convertView;
    }

    static class ViewHolder {
        TextView tv_name;
    }

}